import java.util.Scanner;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:小红的ABC
 * User: wangxin
 * Date: 2024-09-25
 * Time: 16:44
 */
public class test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();
        int n = s.length;
        int ret = -1;
        for (int i = 0; i < n; i++) {
            if (i + 1 < n && s[i + 1] == s[i]) {
                ret = 2;
                break;
            }
            if (i + 2 < n && s[i + 2] == s[i]) {
                ret = 3;
            }
        }
        System.out.println(ret);
    }
}
